Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
¿Se permite el "reformateo" de una matriz multidimensional mediante un puntero a un tipo de matriz incompleto en C?

Considere la siguiente declaración:

 int a[M][N]; // M and N are known compile-time

¿Sería legal tratarlo como se declaró como:

 int a[N][M];

o incluso:

 int a[A][B]; // where A * B = M * N

en C sin romper sus reglas (mal)?

Descubrí que se puede lograr sin ningún tipo de yeso:

 #include <stdio.h> void print_array(int a[][2], int n); int main(void) { int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; //int (*p1)[2] = a; // compile error int (*ptr_temp)[] = a; // pointer to array of incomplete type int (*p2)[2] = ptr_temp; // compiles without any warning print_array(p2, 3); } void print_array(int a[][2], int n) { for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) printf("a[%d][%d] = %d\n", i, j, a[i][j]); }

Tenga en cuenta que no podemos asignar a puntero a p1 directamente. Sin embargo, el compilador no se queja cuando p2 se asigna con ptr_temp , incluso si parece ser potencialmente peligroso (no requiere ninguna conversión para eso). ¿Está realmente desinfectado? Si es así, ¿por qué no permite la primera asignación?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El comportamiento que ve se debe a la forma en que se manejan las matrices multidimensionales en C.

Eche un vistazo a esta preguntaDirección del puntero en una matriz multidimensional C

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!